/* 竞赛项目申报-提交成果 */
<template>
    <div>
        <div v-if="indexKey === 1">
            <div style="height: 30px;">
                <el-breadcrumb style="float: left;" separator="/">
                    <el-breadcrumb-item :to="{ path: '/projectDeclaration' }">
                        <span @click="reback()" >{{ $t('projectDeclara.competiProjectAdd') }}</span>
                    </el-breadcrumb-item>
                    <el-breadcrumb-item>{{ compile }}</el-breadcrumb-item>
                </el-breadcrumb>
            </div>

            <el-card v-loading="loading" shadow="never" body-style="padding: 10px;">
                <el-row style="padding:15px 15px 0 15px;" type="flex" class="row-bg" justify="space-between">
                    <h2>
                        {{$t('collegeFirstTrial.projectDeclara')+'-'+ compile}}
                    </h2>
                    <el-button @click="reback">
                        {{ $t('statisticsOfAwards.goBack') }}
                    </el-button>
                </el-row>
                <hr >
            
                <el-card shadow="never" body-style="padding: 24px;" style="margin: 0;border: none;">
                    <el-form
                        ref="queryForm"
                        :model="queryForm"
                        :rules="rules"
                        label-suffix="："
                        label-position="top"
                    >
                        <el-row :gutter="24">
                            <!-- 学院 -->
                            <el-col :span="8">
                                <el-form-item :label="$t('label.college')">
                                    <!-- <DictSelect v-model="queryForm.departmentId" :data="options.departmentId" :clearable="true" ></DictSelect> -->
                                    <DictSelect disabled :labelAll="$t('statisticsOfAwards.whole')" v-model="queryForm.collegeName" filterable :data="options.departmentId" :clearable="true" @change="getCollegeName(queryForm.college)" ></DictSelect>
                                </el-form-item>
                            </el-col>
                            <!-- 竞赛项目名称 -->
                            <el-col :span="16">
                                <el-form-item :label="$t('statisticsOfAwards.competitionName')">
                                    <el-input
                                        maxlength="100"
                                        disabled
                                        v-model="queryForm.projectName"
                                        :placeholder="$t('statisticsOfAwards.pleaseEnter')"
                                        clearable
                                        style="width: 100%"
                                    >
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <!-- 组织机构 -->
                            <!-- <el-col :span="12">
                                <el-form-item :label="$t('statisticsOfAwards.organStructure')" prop="orgName">
                                    <el-input
                                        maxlength="100"
                                        v-model="queryForm.orgName"
                                        :placeholder="$t('statisticsOfAwards.pleaseEnter')"
                                        clearable
                                        style="width: 100%"
                                    >
                                    </el-input>
                                </el-form-item>
                            </el-col> -->
                        </el-row>
                        <el-row :gutter="24">
                            <!-- 竞赛负责人 -->
                            <el-col :span="8">
                                <el-form-item :label="$t('projectDeclara.competitionLeader')">
                                     <el-input
                                        maxlength="100"
                                        disabled
                                        v-model="queryForm.comManagerName"
                                        :placeholder="$t('statisticsOfAwards.pleaseEnter')"
                                        clearable
                                        style="width: 100%"
                                    >
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <!-- 获奖时间 -->
                            <!-- <el-col :span="6">
                                <el-form-item :label="$t('statisticsOfAwards.awardTime')" prop="awardsDate">
                                    <el-date-picker 
                                    :picker-options="pickerOptionsStart"
                                    type="month" 
                                    :placeholder="$t('请选择')"
                                    v-model="queryForm.awardsDate"
                                    value-format="yyyy-MM"
                                    style="width: 100%;"></el-date-picker>
                                </el-form-item>
                            </el-col> -->
                            <!-- 竞赛时间地点 -->
                            <el-col :span="16">
                                <el-form-item :label="$t('projectDeclara.timeAndPlace')">
                                     <el-input
                                        maxlength="100"
                                        disabled
                                        v-model="queryForm.comPlace"
                                        :placeholder="$t('statisticsOfAwards.pleaseEnter')"
                                        clearable
                                        style="width: 100%"
                                    >
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            
                        </el-row>
                        <el-row :gutter="24">
                            <!-- 竞赛总结 -->
                            <el-col :span="24">
                                <el-form-item :label="$t('projectDeclara.competitionSummary')">
                                    <el-input
                                    type="textarea"
                                    maxlength="10000"
                                    :rows="5"
                                    :placeholder="$t('projectDeclara.competitionSummaryContent')"
                                    v-model="queryForm.contestSummary">
                                    </el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="24">
                            <!-- 组织、参赛经费使用情况 -->
                            <el-col :span="24">
                                <el-form-item :label="$t('projectDeclara.usage')">
                                    <el-input
                                    type="textarea"
                                    maxlength="10000"
                                    :rows="5"
                                    :placeholder="$t('projectDeclara.usageContent')"
                                    v-model="queryForm.usageCondition">
                                    </el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row style="padding:15px;" type="flex" class="row-bg" justify="space-between">
                            <h2>
                                {{$t('projectDeclara.achievementStatistics')}}
                            </h2>
                            <div>
                                <el-button @click="addResults('edit')" v-if="queryForm.awardsInfoList.length > 0" type="primary">
                                    {{ $t('statisticsOfAwards.edit') }}
                                </el-button>
                                <el-button @click="addResults('add')" v-else type="primary">
                                    {{ $t('statisticsOfAwards.adds') }}
                                </el-button>
                            </div>
                        </el-row>
                        <el-row :gutter="24">
                            <!-- 本科学生数 -->
                            <el-col :span="8">
                                <el-form-item :label="$t('projectDeclara.undergraduate')">
                                    <el-input
                                        maxlength="100"
                                        disabled
                                        v-model="queryForm.undergraduate"
                                        :placeholder="$t('statisticsOfAwards.pleaseEnter')"
                                        clearable
                                        style="width: 100%"
                                    >
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <!-- 研究生学生数 -->
                            <el-col :span="8">
                                <el-form-item :label="$t('projectDeclara.graduate')">
                                    <el-input
                                        maxlength="100"
                                        disabled
                                        v-model="queryForm.graduate"
                                        :placeholder="$t('statisticsOfAwards.pleaseEnter')"
                                        clearable
                                        style="width: 100%"
                                    >
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <!-- 主办单位 -->
                            <el-col :span="8">
                                <el-form-item :label="$t('projectDeclara.sponsor')">
                                    <el-input
                                        maxlength="100"
                                        disabled
                                        v-model="queryForm.organizer"
                                        :placeholder="$t('statisticsOfAwards.pleaseEnter')"
                                        clearable
                                        style="width: 100%"
                                    >
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="24" style="margin: 15px 0">
                                <el-table :pagination="false" :order="false" :selection='true' :tooltipEffect="tooltipEffect" stripe :data="queryForm.awardsInfoList" size="mini" :span-method="objectSpanMethod">
                                    <el-table-column :label="$t('statisticsOfAwards.awardLevel')" prop="awardsName" show-overflow-tooltip></el-table-column>
                                    <el-table-column :label="$t('registrationList.titleOfTheWork')" prop="projectTitle" show-overflow-tooltip></el-table-column>
                                    <el-table-column align='center' :label="$t('registrationList.personnelInformation')">
                                        <el-table-column :label="$t('statisticsOfAwards.groups')" prop="termNumber" show-overflow-tooltip></el-table-column>
                                        <el-table-column :label="$t('registrationList.studentId')" prop="studentId" show-overflow-tooltip></el-table-column>
                                        <el-table-column :label="$t('registrationList.studentName')" prop="studentName" show-overflow-tooltip></el-table-column>
                                    </el-table-column>
                                </el-table>
                            </el-col>
                        </el-row>
                        <el-row :gutter="24" style="padding:15px;">
                            <h2>
                                {{$t('projectDeclara.projectTeamInformation')}}
                            </h2>
                            <el-col :span="24" style="margin: 15px 0">
                                <el-table style="margin-top:10px"
                                    :pagination="false"
                                    :selection="false"
                                    :tooltipEffect="tooltipEffect"
                                    stripe
                                    :data="queryForm.lastScoreList"
                                    size="mini">
                                    <el-table-column type="index" label="序号" width="50"></el-table-column>
                                    <el-table-column :label="$t('projectDeclara.schedule')" width="400">
                                        <template slot-scope="scope" >
                                            <el-form-item v-if="!scope.row.flag" style="margin-top: 15px;">
                                                <el-date-picker
                                                    v-model="scope.row.scheduleTime"
                                                    type="daterange"
                                                    format="yyyy-MM-dd"
                                                    value-format="yyyy-MM-dd"
                                                    range-separator="至"
                                                    start-placeholder="开始月份"
                                                    end-placeholder="结束月份"
                                                    style="width: 100%;">
                                                </el-date-picker>
                                            </el-form-item>
                                            <span v-if="scope.row.flag">{{ scope.row.startTime + '至' + scope.row.endTime }}</span>
                                        </template>
                                    </el-table-column>
                                    <el-table-column :label="$t('projectDeclara.workContent')" prop='jobContent'>
                                        <template slot-scope="scope" >
                                            <el-form-item v-if="!scope.row.flag" style="margin-top: 15px;" >
                                                <el-input
                                                    v-model.trim="scope.row.jobContent"
                                                    clearable 
                                                    :placeholder="$t('statisticsOfAwards.pleaseEnter')"
                                                    maxlength="500" >
                                                </el-input>
                                            </el-form-item>
                                            <el-tooltip v-if="scope.row.flag" class="item" effect="dark" :content="scope.row.jobContent" placement="top-start">
                                                <span>{{scope.row.jobContent}}</span>
                                            </el-tooltip>
                                        </template>
                                    </el-table-column>
                                    <el-table-column :label="$t('projectDeclara.duration')" prop="trainTime" >
                                        <template slot-scope="scope">
                                            <el-form-item v-if="!scope.row.flag" style="margin-top: 15px;"  >
                                            <!-- <el-form-item v-if="!scope.row.flag" style="margin-top: 15px;" :prop="'lastScoreList.' + scope.$index + '.result'" label-width="0" :rules="rulesForm.result" > -->
                                                <el-input
                                                    v-model.trim="scope.row.trainTime"
                                                    :placeholder="$t('statisticsOfAwards.pleaseEnter')"
                                                    clearable
                                                    maxlength="16" >
                                                </el-input>
                                            </el-form-item>
                                            <el-tooltip v-else class="item" effect="dark" :content="scope.row.trainTime" placement="top-start">
                                                <span>{{scope.row.trainTime}}</span>
                                            </el-tooltip>
                                        </template>
                                    </el-table-column>
                                    <el-table-column :label="$t('projectDeclara.people')" prop="peopleName" >
                                        <template slot-scope="scope">
                                            <!-- <el-form-item v-if="!scope.row.flag" style="margin-top: 15px;"  >
                                                <el-select
                                                    :placeholder="$t('statisticsOfAwards.pleaseInputNumber')"
                                                    v-model="scope.row.peopleName"
                                                    :remote-method="remoteMethodTow"
                                                    style="width: 100%"
                                                    clearable
                                                    filterable
                                                    remote
                                                    reserve-keyword
                                                    @change="changeInput"
                                                >
                                                    <el-option
                                                        v-for="item in options.name"
                                                        :key="item.studentId"
                                                        @click.native="queryNameClick(item.studentId, scope.row, 'studentId')"
                                                        :label="item.studentName"
                                                        :value="item.studentId"
                                                    >
                                                    </el-option>
                                                </el-select> -->
                                                <!-- <el-input v-if="!scope.row.flag"
                                                    :placeholder="$t('statisticsOfAwards.name')"
                                                    v-model.trim="scope.row.studentName"
                                                    clearable
                                                    maxlength="64"
                                                >
                                                </el-input> -->
                                            <el-form-item v-if="!scope.row.flag" style="margin-top: 15px;" >
                                                <el-input
                                                    v-model.trim="scope.row.peopleName"
                                                    :placeholder="$t('projectDeclara.pleaseInputStudentName')"
                                                    clearable
                                                    maxlength="64" >
                                                </el-input>
                                            </el-form-item>
                                            <el-tooltip v-else class="item" effect="dark" :content="scope.row.peopleName" placement="top-start">
                                                <span>{{scope.row.peopleName}}</span>
                                            </el-tooltip>
                                        </template>
                                    </el-table-column>
                                    <el-table-column :label="$t('common.text.operation')" fit width="150">
                                        <template slot-scope="props">
                                            <el-button type="text" v-if="!props.row.flag"  @click="internAssignment(props.row,props.$index)">{{$t('projectDeclara.save')}}</el-button>
                                            <el-button type="text" v-if="props.row.flag" @click="submitResults(props.row,props.$index)">{{$t('projectDeclara.compile')}}</el-button>
                                            <el-button type="text" v-if="props.row.flag" @click="selectEvalResubmit(props.row,props.$index)">{{$t('projectDeclara.delete')}}</el-button>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </el-col>
                        </el-row>
                        <el-row :gutter="24">
                            <h2 style="margin-left: 10px">
                                {{$t('projectDeclara.projectPressRelease')}}
                            </h2>
                            <el-col :span="24">
                                <el-form-item>
                                    <!-- <el-input
                                    type="textarea"
                                    maxlength="10000"
                                    :rows="5"
                                    :placeholder="$t('projectDeclara.usageContent')"
                                    v-model="queryForm.comLevel">
                                    </el-input> -->
                                    <Tinymce ref="editor" style="margin-top: 20px;" 
                                    :height="400" :simple="false" :hideMenu="true" v-model="queryForm.newsStory" 
                                    :toolbar="toolbar" :showImage="false"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="24">
                            <h2 style="margin-left: 10px">
                                {{$t('projectDeclara.photoUpload')}}
                            </h2>
                            <el-col :span="24">
                                <el-upload
                                    style="display: inline-block;"
                                    action="/api/commonservice/obsfile/uploadimage"
                                    list-type="picture-card"
                                    :data="{bucketname: 'face', folderpath: 'image'}"
                                    :show-file-list="false"
                                    :on-success="handleAvatarSuccess"
                                    :on-preview="handlePictureCardPreview"
                                    :before-upload="beforeAvatarUpload"
                                    :on-remove="handleRemove"
                                    >
                                    <i class="el-icon-plus"></i>
                                </el-upload>
                                <template v-for="item in fileList">
                                    <div style="position: relative;float: left;margin-right: 10px" :key="item.key"> 
                                        <img class="imgStyle" :key="item.key" width="100%" :src="item.value" alt="">
                                        <el-button class="zoom" icon="el-icon-zoom-in" circle @click="preview(item.value)"></el-button>
                                        <el-button class="delete" icon="el-icon-delete" circle @click="remove(item.url)"></el-button>
                                    </div>
                                </template>
                                
                                <el-dialog :visible.sync="dialogVisible">
                                    <img width="100%" :src="dialogImageUrl" alt="">
                                </el-dialog>
                            </el-col>
                        </el-row>
                    </el-form>
                </el-card>
                <div style="float: right; padding: 15px;">
                    <el-button @click="cancel">{{ $t('statisticsOfAwards.cancel') }}</el-button>
                    <el-button type="primary" @click="saves"> {{ $t('statisticsOfAwards.save') }}</el-button>
                </div>
            </el-card>
        </div>
        <!-- 添加 -->
        <div v-if="indexKey === 2">
            <addTeam @add-exam='addExam' :compileType='compileType' :dataList='dataListObj' :studentTeam="studentTeam" :comForm="queryForm.comForm"></addTeam>
        </div>
    </div>
</template>

<script>
// import baseUrl from 'common/src/api/subjectCompetition/env'
import baseUrl from 'common/src/api/innovative/env'
import { queryDic } from 'common/src/api/dictionary'
import UTILS from 'common/src/utils/utils'
import competiManagementApi from 'common/src/api/subjectCompetition/competiManagement'
import interManagementApi from 'common/src/api/externalExchange/interdiSciplinaryManagement'
import Tinymce from "common/src/components/tinymce"
import addTeam from './addTeam'
import { findTeacherInfoList } from 'common/src/api/studentinfo'
import { downloadimage } from 'common/src/api/upload'
export default {
    props: {
        compile: {
            type: String,
            default: ''
        },
        dataList: {
            type: Object,
            default: () => {}
        }
    },
    components: {
        Tinymce,
        addTeam: addTeam
    },
    data() {
        let cannotEnter = (rule, value, callback) => {
            let reg = /[`$]/im
            if (reg.test(value)) {
                return callback(new Error(this.$t('statisticsOfAwards.donotEnterSpecial')))
            } else if (value === '' || value === null) {
                return callback(new Error(this.$t('statisticsOfAwards.pleaseEnter')))
            }
            return callback()
        }
        return {
            queryForm: {
                projectId: this.dataList.projectId, // 竞赛项目名称
                projectName: this.dataList.name, // 竞赛项目名称
                comManagerName: this.dataList.comManagerName, // 作品名称
                comStart: this.dataList.comStart, // 竞赛级别
                comPlace: this.dataList.comStart + '' + this.dataList.comPlace, // 组织机构
                college: this.dataList.college, // 学院
                collegeName: this.dataList.collegeName,// 学院名称
                contestSummary: this.dataList.contestSummary, // 竞赛总结
                usageCondition: this.dataList.usageCondition, // 参赛经费使用情况
                undergraduate: this.dataList.undergraduate, // 本科生数
                graduate: this.dataList.graduate, // 研究生数
                organizer: this.dataList.organizer, // 主办单位
                newsStory: this.dataList.newsStory, // 主办单位
                awardsDate: null, // 获奖时间
                comForm: this.dataList.comForm, // 1团队 2个人
                awardsInfoList: [],
                awardsInfo: {},
                picture: [],
                pictureName: [],
                lastScoreList: [
                    {
                        flag: false,
                        projectId: '',
                        scheduleTime: '',
                        projectId: '',
                        startTime: '',
                        endTime: '',
                        jobContent: '',
                        trainTime: '',
                        people: '',
                        peopleName: '',
                        index: 0
                    }
                ]
            },
            indexKey: 1,
            toolbar: ["undo redo | styleselect | fontselect | formatselect | fontsizeselect | forecolor backcolor | bold italic underline strikethrough | table | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | fullscreen"],
            options: {
                batch: [], // 竞赛级别
                match: [], // 参赛形式
                // time: [], // 获奖时间
                prize: [], // 奖项名称
                name: [], // 姓名
                departmentId: [] // 学院
            },
            dataListObj: {},
            dialogImageUrl: '',
            dialogVisible: false,
            fileList: [],
            spanArr: [], // 一个空的数组，用于存放每一行记录的合并数
            pos: 0, // spanArr 的索引
            contentSpanArr: [],
            position: 0,
            studentAwardsInfoList: [], // 添加学生信息
            undergraduate: [], // 本科生数
            graduate: [], // 研究生数
            studentTeam: [], // 编辑学生信息
            compileType: '', // 编译类型
            isJPG: false, // 图片格式
            isLt2M: false, // 图片大小
            rules: {
                projectName: [
                    {
                        required: true,
                        message: this.$t('statisticsOfAwards.pleaseSelectCompet'),
                        trigger: 'blur'
                    },
                    { validator: cannotEnter, trigger: 'blur' }
                ],
                projectTitle: [
                    {
                        required: true,
                        message: this.$t('statisticsOfAwards.pleaseSelectOpus'),
                        trigger: 'blur'
                    },
                    { validator: cannotEnter, trigger: 'blur' }
                ],
                orgName: [
                    {
                        required: true,
                        message: this.$t('statisticsOfAwards.pleaseSelectOrgan'),
                        trigger: 'blur'
                    },
                    { validator: cannotEnter, trigger: 'blur' }
                ],
                comForm: [
                    {
                        required: true,
                        message: this.$t('statisticsOfAwards.pleaseSelectForm'),
                        trigger: 'change'
                    }
                ],
                awardsDate: [
                    {
                        required: true,
                        message: this.$t('statisticsOfAwards.pleaseSelectTime'),
                        trigger: 'change'
                    },
                ],
                college: [
                    {
                        required: true,
                        message: this.$t('projectInformationStatistics.college'),
                        trigger: 'change'
                    },
                ]
            }
        }
    },
    mounted() {
        this.getOptions()
        if(this.dataList.manageProjectTeamInfoVOS.length > 0) {
            let lastScore = []
            this.dataList.manageProjectTeamInfoVOS.forEach(el => {
                if (el.scheduleTime || el.jobContent || el.trainTime || el.peopleName) { 
                    this.$set(el, 'flag', true)
                    lastScore.push(el)
                } 
            })
            this.queryForm.lastScoreList = lastScore
            this.queryForm.lastScoreList.push(
                {
                    flag: false,
                    projectId: this.dataList.projectId,
                    scheduleTime: '',
                    projectId: '',
                    startTime: '',
                    endTime: '',
                    jobContent: '',
                    trainTime: '',
                    people: '',
                    peopleName: '',
                    index: this.queryForm.lastScoreList.length-1
                }
            )
        }
        if(this.dataList.manageProjectAwardsInfoExcelVOList.length > 0) {
            let infoList = this.dataList.manageProjectAwardsInfoExcelVOList
            infoList.forEach( el => {
                el.termNumber = 1
            })
            this.dataList.manageProjectAwardsInfoExcelVOList.forEach( value => {
                if(value.projId === 1){
                    this.undergraduate.push(value.projId)
                }else {
                    this.graduate.push(value.projId)
                }
            })
            this.queryForm.undergraduate = this.undergraduate.length
            this.queryForm.graduate = this.graduate.length
            this.queryForm.awardsInfoList = infoList
        }
        this.getImg()
        this.mergeCell()
    },
    methods: {
        reback() {
            this.$emit('change-exam')
        },
        // 学号改变获取数据
        remoteMethodTow(query) {
            if (query) {
                setTimeout(() => {
                    interManagementApi.getStudents(query).then(res => {
                        this.options.name = res.data
                    })
                }, 200)
            } else {
                this.options.name = []
            }
        },
        // 学号改变获取数据
        changeInput(val) {
            if (val) {
                interManagementApi.getStudents(val).then(res => {
                    this.options.name = res.data
                })
            } else {
                this.options.name = []
            }
            if (this.options.name) {
                this.options.name.forEach(el => {
                    if (val === el.studentId) {
                        this.options.name.push(el)
                    }
                })
            }
        
        },
        queryNameClick(name, row, str) {
            this.$set(row, str, name)
            this.options.name.forEach(el => {
                if (name === el.studentId) {
                    this.$set(row, 'peopleName', el.studentName)
                    this.$set(row, 'people', el.studentId)
                }
            })
        },
        getOptions() {
            // 筛选条件字典查询
            let data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: ['X_YX', 'G_XBIE', 'JSGL_JSJB', 'G_GJQU', 'JSGL_CSXS', 'JSGL_JXMC']
            }
            queryDic(data).then(res => {
                UTILS.fillSelect(
                    {
                        batch: 'JSGL_JSJB',
                        sex: 'G_XBIE',
                        match: 'JSGL_CSXS',
                        prize: 'JSGL_JXMC',
                        departmentId: "X_YX"
                    },
                    res.data,
                    this.options
                )
            })
        },
        // 获取图片
        getImg() {
            if(this.dataList.picture) {
                this.queryForm.picture = this.dataList.picture.split(",")
                this.queryForm.pictureName = this.dataList.pictureName.split(",")
                this.queryForm.picture.forEach((pic,index) => {
                    downloadimage(pic).then(res => {
                        if (res.code === 200) {
                            this.fileList.push({
                                key: index,
                                value: res.data.base,
                                url: pic
                            });
                        }
                    })
                    
                })
            }
        },
        // 合并单元格
        objectSpanMethod({ row, column, rowIndex, columnIndex }) {
            if (columnIndex === 0) {
                const _row = this.spanArr[rowIndex]
                const _col = _row > 0 ? 1 : 0
                return {
                    rowspan: _row,
                    colspan: _col
                };
            } else if (columnIndex === 1 || columnIndex === 2) {
                const _row = this.contentSpanArr[rowIndex]
                const _col = _row > 0 ? 1 : 0
                return {
                    rowspan: _row,
                    colspan: _col
                };
            }
        },
        // 合并单元格
        mergeCell() {
            if(this.queryForm.awardsInfoList.length > 0) {
                // 设定一个数组spanArr/contentSpanArr来存放要合并的格数，同时还要设定一个变量pos/position来记录
                this.spanArr = []
                this.contentSpanArr = []
                // this.queryForm.awardsInfoList = this.dataList.manageProjectAwardsInfoExcelVOList
                for (var i = 0; i < this.queryForm.awardsInfoList.length; i++) {
                    if (i === 0) {
                        this.spanArr.push(1)
                        this.pos = 0
                        this.contentSpanArr.push(1)
                        this.position = 0
                    } else {
                        // 判断当前元素与上一个元素是否相同(第1和第2列)
                        if (this.queryForm.awardsInfoList[i].projectTitle === this.queryForm.awardsInfoList[i - 1].projectTitle
                            && this.queryForm.awardsInfoList[i].awardsCode === this.queryForm.awardsInfoList[i - 1].awardsCode
                            && this.dataList.comForm === '1') {
                            this.spanArr[this.pos] += 1
                            this.spanArr.push(0)
                        } else {
                            this.spanArr.push(1)
                            this.pos = i
                        }
                        // 判断当前元素与上一个元素是否相同(第3列)
                        if (this.queryForm.awardsInfoList[i].projectTitle === this.queryForm.awardsInfoList[i - 1].projectTitle
                            && this.queryForm.awardsInfoList[i].awardsCode === this.queryForm.awardsInfoList[i - 1].awardsCode
                            && this.dataList.comForm === '1') {
                            this.contentSpanArr[this.position] += 1
                            this.contentSpanArr.push(0)
                        } else {
                            this.contentSpanArr.push(1)
                            this.position = i
                        }
                    }
                }
            }
        },
        // 返回提交成果页
        addExam(data, undergraduate, graduate) {
            if(data) {
                if(data.studentAwardsInfoList.length > 0 && this.compileType === 'add') {
                    this.queryForm.awardsDate = data.awardsDate
                    this.queryForm.undergraduate = undergraduate.length
                    this.queryForm.graduate = graduate.length
                    this.studentAwardsInfoList = data.studentAwardsInfoList
                    this.queryForm.awardsInfoList = this.queryForm.awardsInfoList.concat(this.studentAwardsInfoList)
                    this.mergeCell()
                }else {
                    this.queryForm.awardsDate = data.awardsDate
                    this.queryForm.undergraduate = +undergraduate.length
                    this.queryForm.graduate = +graduate.length
                    this.queryForm.awardsInfoList = data.studentAwardsInfoList
                    this.mergeCell()
                }
                this.queryForm.awardsInfo = data
            }
            this.indexKey = 1
        },
        // 添加/编辑
        addResults(type) {
            this.compileType = type
            this.dataListObj = this.dataList
            if(this.queryForm.comForm) {
                this.options.match.forEach(item => {
                    if(item.value === this.queryForm.comForm) {
                        this.queryForm.comForm = item.label
                    }
                })
            }
            if(type === 'edit') {
                let headEdit = []
                let bodyEdit = []
                this.queryForm.awardsInfoList.forEach((item,index)=>{
                    let indexs = headEdit.indexOf(item.projectTitle)
                    if(indexs === -1) {
                            headEdit.push(item.projectTitle)
                            let editList = {
                                awardsCode: item.awardsCode,
                                awardsName: item.awardsName,
                                instructor: item.instructor,
                                otherAward: '',
                                projectTitle: item.projectTitle,
                                studentList:[{
                                    "studentId": item.studentId,
                                    "studentName": item.studentName,
                                    "projId": item.projId,
                                    "flag": true,
                                }]
                            }
                            bodyEdit.push(editList)
                    }else{
                        bodyEdit[indexs].studentList.push({
                            "studentId": item.studentId,
                            "studentName": item.studentName,
                            "projId": item.projId,
                            "flag": true,
                        })
                    }

                })
                bodyEdit.forEach((value, index) => {
                    value.studentList.push({
                        "studentId": '',
                        "studentName": '',
                        "flag": false,
                    })
                })
                this.studentTeam = bodyEdit
                this.dataListObj.awardsInfo.awardsDate = this.queryForm.awardsDate ? this.queryForm.awardsDate : this.dataList.awardsInfo.awardsDate
            }
            this.indexKey = 2
        },
        // 外面的取消
        cancel() {
            this.$emit('change-exam')
        },
        internAssignment(data, index) {
            if (data.scheduleTime&&data.jobContent&&data.trainTime&&data.peopleName) {
                let reg = /[`$]/im
                let regs = /^\+?[1-9]\d*$/
                if (reg.test(data.scheduleTime)) {
                    this.queryForm.lastScoreList[index].scheduleTime = ''
                    return this.$message.warning(this.$t('identificationToDoList.cannotContain'))
                } 
                if (reg.test(data.jobContent)) {
                    this.queryForm.lastScoreList[index].jobContent = ''
                    return this.$message.warning(this.$t('identificationToDoList.cannotContain'))
                } 
                if (reg.test(data.trainTime)) {
                    this.queryForm.lastScoreList[index].trainTime = ''
                    return this.$message.warning(this.$t('identificationToDoList.cannotContain'))
                }
                if (!regs.test(data.trainTime)) {
                    this.queryForm.lastScoreList[index].trainTime = ''
                    return this.$message.warning(this.$t('projectDeclara.correctTime'))
                }
                if (reg.test(data.peopleName)) {
                    this.queryForm.lastScoreList[index].peopleName = ''
                    return this.$message.warning(this.$t('identificationToDoList.cannotContain'))
                }
                if(Array.isArray(this.queryForm.lastScoreList[index].scheduleTime)) {
                    this.queryForm.lastScoreList[index].startTime = this.queryForm.lastScoreList[index].scheduleTime[0]
                    this.queryForm.lastScoreList[index].endTime = this.queryForm.lastScoreList[index].scheduleTime[1]
                }
                this.queryForm.lastScoreList[index].projectId = this.dataList.projectId
                this.queryForm.lastScoreList[index].people = this.queryForm.lastScoreList[index].peopleName
                this.$set(data,'flag', true)
                if (!data.editFlag) {
                    this.queryForm.lastScoreList.push(
                        {
                            flag: false,
                            scheduleTime: '',
                            projectId: this.dataList.projectId,
                            startTime: '',
                            endTime: '',
                            jobContent: '',
                            trainTime: '',
                            people: '',
                            peopleName: '',
                            index: index + 1
                        }
                    )
                }
                this.$set(data,'editFlag', false)
            } else {
                this.$message.warning('请检查项目团队人员信息是否填写完整')
            }
        },
        // 编辑
        submitResults(data, index) {
            this.$set(data,'flag', false)
            this.$set(data,'editFlag', true)
        },
        // 删除
        selectEvalResubmit(data, index) {
            this.$delConfirm().then(() => {
            this.queryForm.lastScoreList.splice(index,1)
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: this.$t('internship.cancelOpera')
                }); 
            })
        },
        handleRemove(file, fileList) {
            if(file.status === 'success') {
                this.queryForm.picture.forEach((pic, index) => {
                    if(pic === file.response.data.file.objectkey) {
                        this.queryForm.picture.splice(index, 1)
                        this.queryForm.pictureName.splice(index, 1)
                    }
                })
            }
        },
        // 手动删除图片
        remove(data) {
            if(data) {
                this.queryForm.picture.forEach((pic, index) => {
                    if(pic === data) {
                        this.queryForm.picture.splice(index, 1)
                        this.queryForm.pictureName.splice(index, 1)
                        this.fileList.splice(index, 1)
                    }
                })
            }
        },
        handlePictureCardPreview(file, fileList) {
            this.dialogImageUrl = file.url;
            this.dialogVisible = true;
        },
        // 限制图片格式
        beforeAvatarUpload(file, res) {
            this.isJPG = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/jpg';
            this.isLt2M = file.size / 1024 / 1024 < 5;
            if (!this.isJPG) {
               return this.$message.error(this.$t('projectDeclara.isJPG'));
            }
            if (!this.isLt2M) {
               return this.$message.error(this.$t('projectDeclara.isLt5M'));
            }
            // return isJPG && isLt2M;
        },
        // 手动预览图片
        preview(data) {
            this.dialogImageUrl = data;
            this.dialogVisible = true;
        },
        handleAvatarSuccess(res, file, fileList) {
            // this.dialogImageUrl = URL.createObjectURL(file.raw);
            if(this.queryForm.picture.length >= 9) {
                return this.$message.warning(this.$t('projectDeclara.picMax'));
            }
            if(res.code === 200 && this.isJPG && this.isLt2M) {
                this.queryForm.picture.push(res.data.file.objectkey)
                this.queryForm.pictureName.push(res.data.file.fileName)
                this.fileList.push({
                    key: this.fileList.length,
                    value: res.data.file.base,
                    url: res.data.file.objectkey
                });
            }
        },
        handleExceed(files, fileList) {
            this.$message.warning(`最多只能上传 9 张图片`);
        },
        // 保存
        saves() {
            let awardsInfo = []
            let regs = /^\+?[1-9]\d*$/
            // 项目团队人员信息列表
            if(this.queryForm.awardsInfoList.length > 0) {
                this.queryForm.awardsInfoList.forEach( (item, index) => {
                    awardsInfo.push({
                        index: index + 1,
                        awardsName: item.awardsName,
                        projectTitle: item.projectTitle,
                        studentId: item.studentId,
                        awardsCode: item.awardsCode,
                        instructor: item.instructor
                    })
                })
                if(this.dataList.manageProjectAwardsInfoExcelVOList.length > 0 && !this.queryForm.awardsInfo.college) {
                    this.queryForm.awardsInfo = this.dataList.awardsInfo
                }
                this.queryForm.awardsInfo.projectId = this.dataList.projectId
                this.queryForm.awardsInfo.studentAwardsInfoList = awardsInfo
            }
            if(this.queryForm.lastScoreList.length > 0){
                this.queryForm.lastScoreList.forEach((item, index) => {
                    if(!item.jobContent) {
                        this.queryForm.lastScoreList.splice(index, 1)
                    }else if(!item.startTime){
                        item.projectId = this.queryForm.projectId
                        item.startTime = item.scheduleTime[0]
                        item.endTime = item.scheduleTime[1]
                    }else {
                        item.projectId = this.queryForm.projectId
                    }
                    item.people = item.peopleName
                })
            }
            for (const iterator of this.queryForm.lastScoreList) {
                if (!regs.test(iterator.trainTime)) {
                    iterator.trainTime = ''
                    return this.$message.warning(this.$t('projectDeclara.correctTime'))
                }
            }
            if(!this.queryForm.contestSummary) {
                return this.$message.warning(this.$t('projectDeclara.pleaseEnterTheCompetitionSummary'))
            }
            if(!this.queryForm.usageCondition) {
                return this.$message.warning(this.$t('projectDeclara.pleaseEnterTheUsagey'))
            }
            if(!this.queryForm.newsStory) {
                return this.$message.warning(this.$t('projectDeclara.pleaseEnterTheProjectPressRelease'))
            }
            let params = {
                "id": this.dataList.id,
                "projectId": this.queryForm.projectId,
                "contestSummary": this.queryForm.contestSummary,
                "usageCondition": this.queryForm.usageCondition,
                "newsStory": this.queryForm.newsStory,
                "picture": this.queryForm.picture.toString(),
                "pictureName": this.queryForm.pictureName.toString(),
                "awardsInfo": this.queryForm.awardsInfo,
                "manageProjectTeamInfoList": this.queryForm.lastScoreList,
            }
            if(this.dataList.id) {
                competiManagementApi.projectResultModify(params).then(res => {
                    if(res.code === 200) {
                        this.$message.success(this.$t('internship.successfully'));
                        this.$emit('change-exam')
                    }
                });
            }else {
                competiManagementApi.projectResultSave(params).then(res => {
                    if(res.code === 200) {
                        this.$message.success(this.$t('internship.successfully'));
                        this.$emit('change-exam')
                    }
                });
            }
        }
    },
}
</script>

<style lang="scss" scoped>
.inner-breadcrumb {
    .breadcrumb {
        span {
            font-weight: normal;
            color: #aaa;
        }
        a {
            font-weight: normal;
            color: #aaa;
        }
        a:hover {
            color: #409eff;
        }
        .last {
            font-weight: bold !important;
            cursor: default !important;
        }
        .disable {
            cursor: default !important;
        }
    }
}
.imgStyle {
    float: left;
    width: 148px;
    height: 148px;
}
.zoom {
    position: absolute;
    top: 60px;
    left: 40px;
}
.delete {
    position: absolute;
    top: 60px;
    left: 70px;
}
</style>

